package com.kejizhentan.springboot2thymeleaf.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * 处理整个web Controller的异常
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler({ArithmeticException.class,NullPointerException.class})//设置能处理的全局异常类型
    public String handlerArithException(Exception ex){
        log.info("异常是{}"+ex);
        return "login";//视图地址，也能返回ModelAndView
    }
}
